
********************************
*Data preparation for 1st stage*
********************************
*
clear all
set mem 2g
set more off
use MMO_C_regfile
table year mne
cap drop nc8 hs6 export qty
rename iso3_d iso_d
merge 1:1 firmid iso_d year isic using tradeshocksiso
drop if _merge == 2
drop if isic == .
drop _merge
*
drop if year == 1995
*
tab year, gen(yd)
*
*FD variables construction
gen lexport = ln(export)
global nbnc8iso2 " nbnc8iso2  nbnc8iso22 nbnc8iso23"
gen lnbnc8iso2=ln(nbnc8iso2isic)
gen lnbnc8iso22= lnbnc8iso2^2
gen lnbnc8iso23= lnbnc8iso2^3
gen lnbnc8iso24= lnbnc8iso2^4
global lnbnc8iso2 " lnbnc8iso2  lnbnc8iso22 lnbnc8iso23 lnbnc8iso24"
label var lnbnc8iso2 "log count of products firm/destination/isic"
egen firmiso = group(firmid iso2_d isic)
tsset firmiso year
pwcorr theil entrop herf sdlx theilw entropw
*
foreach x of varlist llaborpty llaborpty_def  lratioww* lratiow lratio theil  theil0t entrop herf sdlx theilw entropw lgdp lgdpcap lexport $lnbnc8iso2  $nbnc8iso2 atk* {
qui gen `x'_d1 = D1.`x'
qui gen `x'_d5 = D5.`x'
}
*
global nbnc8iso2_d1 "nbnc8iso2_d1  nbnc8iso22_d1 nbnc8iso23_d1"
*
* TRADE SHOCKs
gen ltradeshock1 = (shrexptimesCHN1)
gen ltradeshock2 = (shrexptimesDEU1)
gen ltradeshock3 = (shrexptimesWLD1)
gen ltradeshock3i = (shrexptimesWLDi1)
gen ltradeshock3w = (shrexptimesWLDt1)
gen ltradeshock3iw = (shrexptimesWLDit1)
*
gen ltradeshock3ci = (shrexptimesCONSO1)
gen ltradeshock3ni = (shrexptimesNBCTRYi1)
gen ltradeshock3ii = (shrexptimesINTFLOW1)
gen ltradeshock3fi = (shrexptimesFIRMS1)
*
gen ltradeshock4 = (shrexptimesCHN2)
gen ltradeshock5 = (shrexptimesDEU2)
gen ltradeshock6 = (shrexptimesWLD2)
gen ltradeshock6i = (shrexptimesWLDi2)
gen ltradeshock6ci = (shrexptimesCONSO2)
gen ltradeshock6ni = (shrexptimesNBCTRYi2)
gen ltradeshock6ii = (shrexptimesINTFLOW2)
gen ltradeshock6fi = (shrexptimesFIRMS2)
*
gen lgdpshock3 = (shrexptimesGDP1)
gen lgdpshock6 = (shrexptimesGDP2)
gen lgdpcapshock3 = (shrexptimesGDPc1)
gen lgdpcapshock6 = (shrexptimesGDPc2)
*FD
gen lgdpshock7 = shrexptimesGDP3
gen lgdpcapshock7 = shrexptimesGDPc3
gen ltradeshock7 = shrexptimesWLD3
gen ltradeshock7i= shrexptimesWLDi3
*
* leads and lags
foreach x of varlist ltradeshock3 ltradeshock3i ltradeshock6 ltradeshock6i lgdpshock3 lgdpshock6 {
qui gen `x'_l2 = L2.`x'
qui gen `x'_l1 = L1.`x'
qui gen `x'_f1 = F1.`x'
qui gen `x'_f2 = F2.`x'
}
*
pwcorr lgdpshock3  lgdp
*
label var lgdpshock3 "log GDP shock"

label var lgdpshock6 "$\tilde{\Delta}$ GDP Shock"
label var lgdpshock6_l1 "$\tilde{\Delta}$ GDP Shock ($ t-1$)"
label var lgdpshock6_f1 "$\tilde{\Delta}$ GDP Shock ($ t+1$)"
label var lgdpshock6_l2 "$\tilde{\Delta}$ GDP Shock ($ t-2$)"
label var lgdpshock6_f2 "$\tilde{\Delta}$ GDP Shock ($ t+2$)"

label var lgdpcapshock3 "log GDP per cap shock"
label var lgdpcapshock6 "$\tilde{\Delta}$ GDP per cap Shock"

label var ltradeshock3 "log trade shock"
label var ltradeshock3_l1 "log trade shock ($ t-1$)"
label var ltradeshock3_f1 "log trade shock ($ t+1$)"
label var ltradeshock3_l2 "log trade shock ($ t-2$)"
label var ltradeshock3_f2 "log trade shock ($ t+2$)"

label var ltradeshock6 "$\tilde{\Delta}$ trade shock"
label var ltradeshock6_l1 "$\tilde{\Delta}$ trade shock ($ t-1$)"
label var ltradeshock6_f1 "$\tilde{\Delta}$ trade shock ($ t+1$)"
label var ltradeshock6_l2 "$\tilde{\Delta}$ trade shock ($ t-2$)"
label var ltradeshock6_f2 "$\tilde{\Delta}$ trade shock ($ t+2$)"

label var ltradeshock3i "log trade shock - ISIC"
label var ltradeshock3i_l1 "log trade shock - ISIC ($ t-1$)"
label var ltradeshock3i_f1 "log trade shock - ISIC ($ t+1$)"
label var ltradeshock3i_l2 "log trade shock - ISIC ($ t-2$)"
label var ltradeshock3i_f2 "log trade shock - ISIC ($ t+2$)"

label var ltradeshock6i "$\tilde{\Delta}$ trade shock - ISIC"
label var ltradeshock6i_l1 "$\tilde{\Delta}$ trade shock - ISIC ($ t-1$)"
label var ltradeshock6i_f1 "$\tilde{\Delta}$ trade shock - ISIC ($ t+1$)"
label var ltradeshock6i_l2"$\tilde{\Delta}$ trade shock - ISIC ($ t-2$)"
label var ltradeshock6i_f2 "$\tilde{\Delta}$ trade shock - ISIC ($ t+2$)"

label var ltradeshock3ii "Int. Trade Shock - ISIC"
label var ltradeshock6ii "$\tilde{\Delta}$ Int. Trade Shock - ISIC"
*
label var theilw " Skewness of World Exports (Theil)"
label var theilw_d1 " $ \Delta$ Skewness"
label var lgdp " log GDP"
label var lgdpcap " log GDP per cap"
label var lgdp_d1 " $ \Delta$ log GDP"
label var lgdpcap_d1 " $ \Delta$ log GDP per cap"
label var theil_d1 " $ \Delta$ Skewness"
label var herf_d1 " $ \Delta$ Herfindhal index"
label var sdlx_d1 " $ \Delta$ s.d. ln exports"
*
save temp,replace
